<?php

use App\Http\Controllers\Web\V1\WebsocketHandler;
use App\Models\StudentResult;
use BeyondCode\LaravelWebSockets\Facades\WebSocketsRouter;
use Illuminate\Support\Facades\Route;

$api = app('Dingo\Api\Routing\Router');

$params = [
    'middleware' => ['api'],
    'limit' => 60,
    'expires' => 1
];

Route::get('/{id}', function (\Illuminate\Http\Request $request) {
    $data = StudentResult::query()
        ->where('examination_id', $request->route()->parameter('id'))
        ->where('user_id', 1)->value('content');

    return view('welcome', ['data' => $data]);
});

WebSocketsRouter::webSocket('/liam/hao/app/{appKey}', WebsocketHandler::class);

$api->version('v1', $params, function ($api) {
    $api->group(['namespace' => 'App\Http\Controllers\Web\V1'], function ($api) {
        $api->group(['middleware' => ['api.auth']], function ($api) {
            //前台首页
            $api->get('index', 'IndexController@index')->name('home');

            // 我的考试
            $api->get('exam', 'ExamController@index')->name('exam.index');
            // 进入考试考场
            $api->get('exam/get', 'ExamController@get')->name('exam.get');
            // 进入考试
            $api->post('exam/store', 'ExamController@store')->name('exam.store');

            // 我的练习
            $api->get('my_exercise', 'MyExerciseController@index')->name('myExercise');
            // 进入练习考场
            $api->get('my_exercise/get', 'MyExerciseController@get')->name('myExercise.get');
            // 进入考试
            $api->post('my_exercise/store', 'MyExerciseController@store')->name('myExercise.store');

            // 我的闯关
            $api->get('emigrated', 'EmigratedController@index')->name('emigrated.index');
            // 去闯关
            $api->get('emigrated/get', 'EmigratedController@get')->name('emigrated.get');
            // 开始闯关
            $api->post('emigrated/start', 'EmigratedController@store')->name('emigrated.store');
            // 下一关
            $api->post('emigrated/next', 'EmigratedController@next')->name('emigrated.next');

            // 我的成绩
            $api->get('result', 'ResultController@index')->name('result.index');
            // 我的成绩详情
            $api->get('result/{result}', 'ResultController@show')->name('result.show');

            // 错题数量
            $api->get('redo', 'RedoController@index')->name('redo.index');
            // 错题详情列表
            $api->get('redo/list/{type}', 'RedoController@list')->name('redo.list');
            //错题重做
            $api->post('redo/restart/{redo}', 'RedoController@restart')->name('redo.restart');
            // 移除错题
            $api->delete('redo/delete/{redo}', 'RedoController@delete')->name('redo.delete');

            //我的积分
            $api->get('integrals', 'IntegralController@index')->name('integral.index');
            //我的排行
            $api->get('ranks/{type}', 'RankController@index')->name('rank.index');

            // 技术帮助
            $api->get('help', 'HelpController@index')->name('help');

            // 自主练习
            $api->get('selfExercise', 'SelfExerciseController@index')->name('selfExercise');
            $api->post('selfExercise/show', 'SelfExerciseController@show')->name('selfExercise.show');
            // 自主练习试题单题提交
            $api->post('selfExercise/correct', 'SelfExerciseController@correct')->name('selfExercise.correct');

            // 考试试卷提交
            $api->post('correct/{studentResult}', 'CorrectController@index')->name('correct');
        });
    });
});
